package cn.lyjuan.payment.third.http.api;

import cn.lyjuan.base.exception.ExceptionResolver;
import cn.lyjuan.base.http.filter.LoggingFilter;
import cn.lyjuan.base.util.SpringContextHolder;
import cn.lyjuan.payment.third.base.model.ModelApplication;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import tk.mybatis.spring.annotation.MapperScan;


@SpringBootApplication
@ComponentScan(basePackages = {"cn.lyjuan.payment", "cn.lyjuan.base.mybatis"})
@EnableTransactionManagement
//@ComponentScan(basePackageClasses = {PayApplication.class, CommonApplication.class, ModelApplication.class, ApiApplication.class})
@MapperScan(
        basePackages = {"cn.lyjuan.payment.third.base.common.mapper"
                , "cn.lyjuan.payment.third.base.model.*.mapper"})
@EnableAspectJAutoProxy
@Slf4j
public class ApiApplication extends ModelApplication {
    @Bean
    public SpringContextHolder springContextHolder(ApplicationContext ctx) {
        SpringContextHolder holder = new SpringContextHolder();
        holder.setApplicationContext(ctx);
        return holder;
    }

    @Bean
    public LoggingFilter logFilter() {
        return new LoggingFilter();
    }

    /**
     * 请求日志
     * @return
     */

    /**
     * 异常处理
     *
     * @return
     */
    @Bean
    public ExceptionResolver exceptionResolver() {
        return new ExceptionResolver();
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(ApiApplication.class);
    }
}
